//
//  NSString+Extensions.m
//  Mobil Izleme
//
//  Created by Mehmet Sinan Şahin on 1/2/12.
//  Copyright (c) 2012 netgis. All rights reserved.
//

#import "NSString+Extensions.h"
#import "NGUtility.h"

@implementation NSString (Extensions)

- (int) indexOf:(NSString *)text {
    NSRange range = [self rangeOfString:text];
    if ( range.length > 0 ) {
        return range.location;
    } else {
        return -1;
    }
}

+(BOOL)isEmpty:(NSString *)text {
    return  (text == nil || [@"" isEqualToString:text]);
}

/**
 * dd-MM-yyyy HH:mm:ss -> date
 */
- (NSDate *) toDate {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:DATE_PATTERN]; //this is the sqlite's format
    NSDate *date = [formatter dateFromString:self];
    
    [formatter release];
    return date;
}

/**
 * dd.MM.yyyy HH:mm:ss -> date
 */
- (NSDate *)toDateWithDot {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:DATE_PATTERN_WITH_DOT];
    NSDate *date = [formatter dateFromString:self];
    
    [formatter release];
    return date; 
}

@end
